#define _CRT_SECURE_NO_WARNINGS

class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int ret = 0;
        for (int i = 0; i < prices.size() - 1; i++)
        {
            if (prices[i] < prices[i + 1])
                ret += (prices[i + 1] - prices[i]);
        }
        return ret;
    }
};

class Solution {
public:
    bool canJump(vector<int>& nums) {
        if (nums.size() == 1)
            return true;
        for (int i = nums.size() - 2; i >= 0; i--)
        {
            if (nums[i] == 0)
            {
                if (i == 0)
                    return false;
                else
                {
                    int falg = 0;
                    for (int j = i - 1; j >= 0; j--)
                    {
                        if ((i - j) < nums[j])
                        {
                            falg = 1;
                            break;
                        }
                    }
                    if (falg == 0)
                        return false;
                }
            }
        }
        return true;
    }
};

class Solution {
public:
    bool canJump(vector<int>& nums) {
        if (nums.size() == 1)
            return true;
        int cover = 0;
        for (int i = 0; i <= cover; i++)
        {
            cover = (cover >= i + nums[i]) ? cover : i + nums[i];
            if (cover >= nums.size() - 1)
                return true;
        }
        return false;
    }
};

class Solution {
public:
    int jump(vector<int>& nums) {
        if (nums.size() == 1)
            return 0;
        int cover = 0;
        int max_cover = 0;
        int ret = 0;
        for (int i = 0; i < nums.size(); i++)
        {
            max_cover = max(nums[i] + i, max_cover);
            if (i == cover)
            {
                if (cover < nums.size() - 1)
                    ++ret;
                else
                    break;
                cover = max_cover;
            }
        }
        return ret;
    }
};